package com.deng.storage.controller;

import com.deng.storage.model.entity.Account;
import com.deng.storage.service.impl.AccountServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author 邓天天
 * @date 2021/4/7 20:14
 */
@RestController
@RequestMapping("/storage")
public class StorageController {


    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private AccountServiceImpl accountService;

    @Value("${spring.datasource.url}")
    private String url;

    @GetMapping("/hello")
    public String hello() {
        return "你好，这里是仓储服务";
    }

    @GetMapping("/echo")
    public String echo() {
        return restTemplate.getForObject("http://order-service/hello",String.class);
    }

    @GetMapping("/echo2")
    public String account() {
        return restTemplate.getForObject("http://account-service/hello",String.class);
        //return HttpUtil.get("http://account-service/hello");
    }

    @GetMapping("/url")
    public String getUrl() {
        return url;
    }

    @GetMapping("/account/id")
    public Account getAccount(Integer id) {
        return accountService.getAccount(id);
    }
}
